// mock 模拟数据的
let Mock = require('mockjs');
let area_arr = require('./area.json');
let pi = Math.ceil(Math.random() * 23);
let province = area_arr[pi]
let citys = province.childs.map((item) => {
  return item.name
})
// let ci = Math.ceil(Math.random()*citys.length); 
// let city = province.childs[ci]
let num = Mock.mock({
  "obj|30": [{
    "id": "@increment",
    "searchValue": null,
    "createBy": null,
    "createTime": "@datetime",
    "updateBy": null,
    "updateTime": "@datetime",
    "remark": null,
    "params|3-5": {
      "110000": "看房方便",
      "120000": "独卫",
      "130000": "独立阳台",
      "140000": "智能锁",
      "150000": "免物业费",
      "160000": "地铁近",
      "170000": "学校近"
    },
    "type|1": ["整租", "合租"],
    "houseNum|1": ["一室", "两室", "三室"],
    "houseHall|1": ["一厅", "两厅", "三厅"],
    "toiletNum|1": ["一卫", "两卫", "三卫"],
    "houseCode": function () { return this.houseNum + this.houseHall + this.toiletNum },
    "houseArea|60-200": 100,
    "houseNo": /[1-9]\d{2,3}/,
    "roomCode": /[A-Z]\-[1-6]\-[1-9]0[1-3]/,
    "roomType|1": ["主卧", "次卧"],
    "roomArea|10-100": 100,
    "direction|1": ["南北", '东西'],
    "decoration|1": ["精装", "简装", "豪华", "商品房"],
    "price": /[1-9]\d00/,
    "startDate": "@date",
    "state": "出租",
    "floor": null,
    "stepType": null,
    "introduce": function () { return `位于浦东区张江板块的中部偏西区域，小区于2006年峻工，物业地址是：晨晖路825弄。是由上海张江微电子港有限公司开发建设，小区总建筑面积约160000㎡，容积率约1.4，约有52栋商品房住宅，是由小高层和高层组成，小区内户型有2-5居室，户型面积约74㎡-254㎡，户型方正，适合刚需和改善型人群; 小区绿化率约40%，环境较好。小区是对口的学校依次是：张江集团中学和张江高科实验小学（藿香路校区）和经典幼儿园。` },
    "villageId": "@id",
    "villageName|1": ["独栋高端公寓","越秀星汇尚城","迪凯运河印象","万科杭宸","昌运里","宝嘉誉峰","嘉泰馨庭","锦文雅苑","天鸿香榭里","金昌苑", "锦秀文澜阁", "锦绣雷庭", "紫金苑", "中央公馆", "云海山庄", "洲际观天下"],
    "villageCity|1": citys,
    "village": null,
    "villageyear": "@date",
    "villagetype|1": ["复式户型", "电梯平层Ⅰ（平层两房+三房）", "电梯平层Ⅱ（小三房）", "电梯平层Ⅲ（大三房）", "电梯顶楼复式"],
    "villagegreen|10-100": 100,
    "villageintroduce": function () { return `位于浦东区张江板块的中部偏西区域，小区于2006年峻工，物业地址是：晨晖路825弄。是由上海张江微电子港有限公司开发建设，小区总建筑面积约160000㎡，容积率约1.4，约有52栋商品房住宅，是由小高层和高层组成，小区内户型有2-5居室，户型面积约74㎡-254㎡，户型方正，适合刚需和改善型人群; 小区绿化率约40%，环境较好。小区是对口的学校依次是：张江集团中学和张江高科实验小学（藿香路校区）和经典幼儿园。` },
    "address": function () { return province.name + this.villageCity + "东吴路与通运口交叉口" },
    "code": /[1-9]\d{9}/,
    "payType|1": ["月付", "周付", "季付", "年付"],
    "publishId": "@id",
    "agentName": "@cname",
    "agentPhone": /^1[3456789]\d{9}$/,
    "agentAvatar": "https://cdn.uviewui.com/uview/album/1.jpg",
    "agentUserId": "@id",
    "ownerName": "@cname",
    "owerPhone": /^1[3456789]\d{9}$/,
    "createName": "@datetime",
    "updateName": "@datetime",
    "faceUrl|1": ["https://sourcebyte.vip/profile/upload/2023/03/21/83d8ae46-3b9e-4605-bd4a-b81b70e0e962.jpg",
      "https://sourcebyte.vip/profile/upload/2022/12/21/514dda76-6acf-43cc-9d93-e8ef0dc631ae.jpg",
      "https://sourcebyte.vip/profile/upload/2022/12/21/f0ca48d7-ca6b-48ee-a9f6-5fc5a39dfb69.jpg",
      "https://sourcebyte.vip/profile/upload/2022/12/17/4ab0ad93-6166-4bbc-a715-ac59b0f736ab.jpg",
      "https://sourcebyte.vip/profile/upload/2022/12/16/8e99c268-d170-4fe9-aead-602de13768b6.jpg",
      "https://sourcebyte.vip/profile/upload/2022/12/16/fe37a124-b725-4f97-bb89-e128b50e6516.jpg"],
    "imageList": function () {
      let arry = ["https://sourcebyte.vip/profile/upload/2023/03/21/83d8ae46-3b9e-4605-bd4a-b81b70e0e962.jpg",
        "https://sourcebyte.vip/profile/upload/2022/12/21/514dda76-6acf-43cc-9d93-e8ef0dc631ae.jpg",
        "https://sourcebyte.vip/profile/upload/2022/12/21/f0ca48d7-ca6b-48ee-a9f6-5fc5a39dfb69.jpg",
        "https://sourcebyte.vip/profile/upload/2022/12/17/4ab0ad93-6166-4bbc-a715-ac59b0f736ab.jpg",
        "https://sourcebyte.vip/profile/upload/2022/12/16/8e99c268-d170-4fe9-aead-602de13768b6.jpg",
        "https://sourcebyte.vip/profile/upload/2022/12/16/fe37a124-b725-4f97-bb89-e128b50e6516.jpg"]
      return arry.slice(0, Math.round(Math.random() * arry.length))
    },
    "featureList": null,
    "feature": null,
    "heart": false,
    "longitude": "120.12197",
    "latitude": "30.3405"
  }]
})
let houselist = num.obj
// 查询租房的信息,默认从第一页查询,每页10条,search 查询条件
let searchHouse = function (page = 1, limit = 10, search = {}) {
  let { villageName, housetype, price, houseNum } = search
  // this.findHouseList()
  let searchlist = [...houselist]
  // console.log("searchHouse",search)
  console.log(villageName,housetype,price,houseNum)
  if (villageName!= "null"&&villageName) {
    searchlist= searchlist.filter((item) => {
      return item.villageName.includes(villageName)
    })
  }
  if (housetype!= "null"&&housetype) {
    searchlist= searchlist.filter((item) => {
      return item.type == housetype
    })
  }
  if (price!= "null"&&price) {
    searchlist= searchlist.filter((item) => {
      return item.price <= price && item.price >= price - 1000
    })
  }
  if (houseNum!= "undefined"&&houseNum) {
    searchlist= searchlist.filter((item) => {
      return item.params.includes(houseNum)
    })
  }
  let start = (page - 1) * limit;
  let end = page * limit;
  return searchlist.slice(start, end);
}
// 整租||合租
let addhouse=function (model) {
  // model.id = houselist[houselist.length-1].id+1
  model.id = Mock.mock('@increment')
  houselist.unshift(model)
  return model
}

module.exports = {
  houselist,
  searchHouse,
  addhouse
}